<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.min.js"></script>
</head>
<body>

	<table align="center">
		<caption>
			<span id="">
				产品表
			</span>
			<div id="">
				<button id="addbut" >添加</button>
				<button id="updatebut">修改</button>
				<button id="removebut">删除</button>
			</div>
		</caption>
		<tr>
			<th><input type="checkbox"  /></th>
			<th>序号</th>
			<th>产品编号</th>
			<th>产品名称</th>
			<th>产品类型</th>
			<th>价格</th>
			<th>库存</th>
			<th>描述</th>
		</tr>
		<form action="${pageContext.request.contextPath}/proremoves" method="post">
		<c:forEach items="${productList}" var="p" varStatus="cou">
			<tr>
				<td><input type="checkbox" name="ids"  value="${p.pid}" /></td>
				<td>${cou.index}</td>
				<td>${p.pid}</td>
				<td><a href="${pageContext.request.contextPath}/profindById?pid=${p.pid}">${p.pname}</a></td>
				<td>${p.ptype}</td>
				<td>${p.price}</td>
				<td>${p.pnum}</td>
				<td>${p.content}</td>
				<td>
					<a href="${pageContext.request.contextPath}/proupdateFind?pid=${p.pid}">修改</a>
					<a href="${pageContext.request.contextPath}/proremove?pid=${p.pid}">删除</a>
				</td>
			</tr>
		</c:forEach>
		</form>
	</table>
<s:debug></s:debug>
</body>
<script type="text/javascript">

	
	$(function(){
		// 增删改成功后的提示
		var message = "${messNum}";
		if(message!=""&&message>0){
			alert("操作成功");
		}else if(message!=""&&message<=0){
			alert("操作失败");
		}
		
		$("#addbut").click(function(){
			// 跳转添加页面
			window.location.href="${pageContext.request.contextPath}/page/add.jsp"
		});
		
		$("#removebut").click(function(){
			var $cked = $("td>input:checked"); 
			// 判断被选中的数量
			if($cked.length==0){
				alert("请选中要删除的数据");
			}else{
				var b=confirm("确认删除这"+($cked.length)+"条数据？");
				if(b){
					// 提交表单
					$("form").submit();
				}
			}
			
		});
		
		// 全选功能
		$("th>input").click(function(){
			
			$("td>input").attr("checked",this.checked);
		});
		
	});

</script>

</html>